// var i;
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_EventConfig = require("./AL_GAME_HUA_EventConfig");
// var AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");
// var AL_GAME_HUA_CoinShopBar = require("./AL_GAME_HUA_CoinShopBar");
// var P = cc._decorator;
// var g = P.ccclass;
// var y = P.property;
// var m =
//     (P.menu,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.node_content = null;
//             t.node_shop_coin_bar = null;
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.xianshi_dongzuo = function () {
//             return Promise.resolve();
//         };
//         t.prototype.yincang_dongzuo = function () {
//             return Promise.resolve();
//         };
//         t.prototype.zhixing_chushihua_chuli = function () {
//             var e = this;
//             AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
//                 target: this.node,
//                 showGold: !0,
//                 goldButtonEnable: !1
//             });
//             for (var t = 0; t < 5; t++) {
//                 var n = cc.instantiate(this.node_shop_coin_bar);
//                 n.active = !0;
//                 n.parent = this.node_content;
//             }
//             var o = this.node_content.children;
//             o[0].getComponent(AL_GAME_HUA_CoinShopBar.default).zhixing_chushihua_chuli({
//                 bgId: 0,
//                 goodInfo: AL_GAME_HUA_GoodsConfig.GoodsConfig.getInstance().huoqu_shangpin_miaoshu(
//                     AL_GAME_HUA_GoodsConfig.GoodsId.gold
//                 ),
//                 count: AL_GAME_HUA_GameConst.GameConst.getInstance().reward_coin,
//                 onBuy: function (t) {
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_jieshou_mianban({
//                         rewards: [
//                             {
//                                 goodsId: AL_GAME_HUA_GoodsConfig.GoodsId.gold,
//                                 num: AL_GAME_HUA_GameConst.GameConst.getInstance().reward_coin
//                             }
//                         ]
//                     });
//                     AL_GAME_HUA_Common.Common.bofang_yinxiao("game_coinscollect", e);
//                     AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
//                         source: AL_GAME_HUA_EventConfig.AssetsSource.coin,
//                         action:
//                             2 == t
//                                 ? AL_GAME_HUA_EventConfig.AssetsAction.video_get
//                                 : AL_GAME_HUA_EventConfig.AssetsAction.share_get,
//                         goodsList: [
//                             {
//                                 goods: AL_GAME_HUA_GoodsConfig.GoodsId.gold,
//                                 num: AL_GAME_HUA_GameConst.GameConst.getInstance().reward_coin
//                             }
//                         ]
//                     });
//                 }
//             });
//             o[1].getComponent(AL_GAME_HUA_CoinShopBar.default).zhixing_chushihua_chuli({
//                 bgId: 1,
//                 goodInfo: AL_GAME_HUA_GoodsConfig.GoodsConfig.getInstance().huoqu_shangpin_miaoshu(
//                     AL_GAME_HUA_GoodsConfig.GoodsId.prop_prompt
//                 ),
//                 count: 1,
//                 price: AL_GAME_HUA_GameConst.GameConst.getInstance().prop3_price,
//                 onBuy: function (t) {
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_jieshou_mianban({
//                         rewards: [
//                             {
//                                 goodsId: AL_GAME_HUA_GoodsConfig.GoodsId.prop_prompt,
//                                 num: 1
//                             }
//                         ]
//                     });
//                     AL_GAME_HUA_Common.Common.bofang_yinxiao("game_coinscollect", e);
//                     0 == t
//                         ? AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportTransform({
//                               source: AL_GAME_HUA_EventConfig.AssetsSource.coin,
//                               action: AL_GAME_HUA_EventConfig.AssetsAction.coin_get,
//                               goodsList: [
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.gold,
//                                       num: -AL_GAME_HUA_GameConst.GameConst.getInstance().prop3_price
//                                   },
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.prop_prompt,
//                                       num: 1
//                                   }
//                               ]
//                           })
//                         : AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
//                               source: AL_GAME_HUA_EventConfig.AssetsSource.coin,
//                               action:
//                                   2 == t
//                                       ? AL_GAME_HUA_EventConfig.AssetsAction.video_get
//                                       : AL_GAME_HUA_EventConfig.AssetsAction.share_get,
//                               goodsList: [
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.prop_prompt,
//                                       num: 1
//                                   }
//                               ]
//                           });
//                 }
//             });
//             o[2].getComponent(AL_GAME_HUA_CoinShopBar.default).zhixing_chushihua_chuli({
//                 bgId: 1,
//                 goodInfo: AL_GAME_HUA_GoodsConfig.GoodsConfig.getInstance().huoqu_shangpin_miaoshu(
//                     AL_GAME_HUA_GoodsConfig.GoodsId.prop_brush
//                 ),
//                 count: 1,
//                 price: AL_GAME_HUA_GameConst.GameConst.getInstance().prop5_price,
//                 onBuy: function (t) {
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_jieshou_mianban({
//                         rewards: [
//                             {
//                                 goodsId: AL_GAME_HUA_GoodsConfig.GoodsId.prop_brush,
//                                 num: 1
//                             }
//                         ]
//                     });
//                     AL_GAME_HUA_Common.Common.bofang_yinxiao("game_coinscollect", e);
//                     0 == t
//                         ? AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportTransform({
//                               source: AL_GAME_HUA_EventConfig.AssetsSource.coin,
//                               action: AL_GAME_HUA_EventConfig.AssetsAction.coin_get,
//                               goodsList: [
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.gold,
//                                       num: -AL_GAME_HUA_GameConst.GameConst.getInstance().prop5_price
//                                   },
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.prop_brush,
//                                       num: 1
//                                   }
//                               ]
//                           })
//                         : AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
//                               source: AL_GAME_HUA_EventConfig.AssetsSource.coin,
//                               action:
//                                   2 == t
//                                       ? AL_GAME_HUA_EventConfig.AssetsAction.video_get
//                                       : AL_GAME_HUA_EventConfig.AssetsAction.share_get,
//                               goodsList: [
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.prop_brush,
//                                       num: 1
//                                   }
//                               ]
//                           });
//                 }
//             });
//             o[3].getComponent(AL_GAME_HUA_CoinShopBar.default).zhixing_chushihua_chuli({
//                 bgId: 1,
//                 goodInfo: AL_GAME_HUA_GoodsConfig.GoodsConfig.getInstance().huoqu_shangpin_miaoshu(
//                     AL_GAME_HUA_GoodsConfig.GoodsId.prop_freeze
//                 ),
//                 count: 1,
//                 price: AL_GAME_HUA_GameConst.GameConst.getInstance().prop6_price,
//                 onBuy: function (t) {
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_jieshou_mianban({
//                         rewards: [
//                             {
//                                 goodsId: AL_GAME_HUA_GoodsConfig.GoodsId.prop_freeze,
//                                 num: 1
//                             }
//                         ]
//                     });
//                     AL_GAME_HUA_Common.Common.bofang_yinxiao("game_coinscollect", e);
//                     0 == t
//                         ? AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportTransform({
//                               source: AL_GAME_HUA_EventConfig.AssetsSource.coin,
//                               action: AL_GAME_HUA_EventConfig.AssetsAction.coin_get,
//                               goodsList: [
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.gold,
//                                       num: -AL_GAME_HUA_GameConst.GameConst.getInstance().prop6_price
//                                   },
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.prop_freeze,
//                                       num: 1
//                                   }
//                               ]
//                           })
//                         : AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
//                               source: AL_GAME_HUA_EventConfig.AssetsSource.coin,
//                               action:
//                                   2 == t
//                                       ? AL_GAME_HUA_EventConfig.AssetsAction.video_get
//                                       : AL_GAME_HUA_EventConfig.AssetsAction.share_get,
//                               goodsList: [
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.prop_freeze,
//                                       num: 1
//                                   }
//                               ]
//                           });
//                 }
//             });
//             o[4].getComponent(AL_GAME_HUA_CoinShopBar.default).zhixing_chushihua_chuli({
//                 bgId: 1,
//                 goodInfo: AL_GAME_HUA_GoodsConfig.GoodsConfig.getInstance().huoqu_shangpin_miaoshu(
//                     AL_GAME_HUA_GoodsConfig.GoodsId.prop_reset
//                 ),
//                 count: 1,
//                 price: AL_GAME_HUA_GameConst.GameConst.getInstance().prop4_price,
//                 onBuy: function (t) {
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_jieshou_mianban({
//                         rewards: [
//                             {
//                                 goodsId: AL_GAME_HUA_GoodsConfig.GoodsId.prop_reset,
//                                 num: 1
//                             }
//                         ]
//                     });
//                     AL_GAME_HUA_Common.Common.bofang_yinxiao("game_coinscollect", e);
//                     0 == t
//                         ? AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportTransform({
//                               source: AL_GAME_HUA_EventConfig.AssetsSource.coin,
//                               action: AL_GAME_HUA_EventConfig.AssetsAction.coin_get,
//                               goodsList: [
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.gold,
//                                       num: -AL_GAME_HUA_GameConst.GameConst.getInstance().prop4_price
//                                   },
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.prop_reset,
//                                       num: 1
//                                   }
//                               ]
//                           })
//                         : AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput({
//                               source: AL_GAME_HUA_EventConfig.AssetsSource.coin,
//                               action:
//                                   2 == t
//                                       ? AL_GAME_HUA_EventConfig.AssetsAction.video_get
//                                       : AL_GAME_HUA_EventConfig.AssetsAction.share_get,
//                               goodsList: [
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.prop_reset,
//                                       num: 1
//                                   }
//                               ]
//                           });
//                 }
//             });
//         };
//         t.prototype.start = function () {};
//         t.prototype.onEnable = function () {
//             AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//                 node: this.node,
//                 hide: !0
//             });
//         };
//         t.prototype.onDisable = function () {
//             AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
//                 node: this.node,
//                 hide: !1
//             });
//         };
//         t.prototype.handle_button_callback = function (e, t) {
//             switch (t) {
//                 case "close":
//                     this.close();
//             }
//             this.xianshi_block_top();
//         };
//         __decorate([y(cc.Node)], t.prototype, "node_content", void 0);
//         __decorate([y(cc.Node)], t.prototype, "node_shop_coin_bar", void 0);
//         return __decorate([g], t);
//     })(AL_GAME_HUA_PopupSelf.default));
// exports.default = m;

// 引入所需模块
const AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
const AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
const AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
const AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
const AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
const AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
const AL_GAME_HUA_EventConfig = require("./AL_GAME_HUA_EventConfig");
const AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");
const AL_GAME_HUA_CoinShopBar = require("./AL_GAME_HUA_CoinShopBar");

const { ccclass, property } = cc._decorator;

/**
 * CoinShop 类 - 控制货币商店类的弹窗和商品初始化
 */
@ccclass
class CoinShop extends AL_GAME_HUA_PopupSelf.default {
    @property(cc.Node)
    node_content = null;

    @property(cc.Node)
    node_shop_coin_bar = null;

    // 初始化商店
    zhixing_chushihua_chuli() {
        const self = this;

        AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
            target: this.node,
            showGold: true,
            goldButtonEnable: false
        });

        // 初始化商店栏位
        for (let i = 0; i < 5; i++) {
            const coinShopInstance = cc.instantiate(this.node_shop_coin_bar);
            coinShopInstance.active = true;
            coinShopInstance.parent = this.node_content;
        }

        const goodsData = [
            { id: 'gold', price: null, count: AL_GAME_HUA_GameConst.GameConst.getInstance().reward_coin },
            { id: 'prop_prompt', price: AL_GAME_HUA_GameConst.GameConst.getInstance().prop3_price, count: 1 },
            { id: 'prop_brush', price: AL_GAME_HUA_GameConst.GameConst.getInstance().prop5_price, count: 1 },
            { id: 'prop_freeze', price: AL_GAME_HUA_GameConst.GameConst.getInstance().prop6_price, count: 1 },
            { id: 'prop_reset', price: AL_GAME_HUA_GameConst.GameConst.getInstance().prop4_price, count: 1 }
        ];

        goodsData.forEach((data, index) => {
            const component = this.node_content.children[index].getComponent(AL_GAME_HUA_CoinShopBar.default);
            const goodInfo = AL_GAME_HUA_GoodsConfig.GoodsConfig.getInstance().huoqu_shangpin_miaoshu(
                AL_GAME_HUA_GoodsConfig.GoodsId[data.id]
            );

            component.zhixing_chushihua_chuli({
                bgId: index === 0 ? 0 : 1,  // 假设仅第一个商品不同背景
                goodInfo,
                count: data.count,
                price: data.price,
                onBuy: (type) => buyHandler(type, data.id, data.count, data.price, self)
            });
        });
    }

    xianshi_dongzuo() {
        return Promise.resolve();
    }

    yincang_dongzuo() {
        return Promise.resolve();
    }

    start() {}

    onEnable() {
        AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
            node: this.node,
            hide: true
        });
    }

    onDisable() {
        AL_APP_SDK_MANAGER.emit(AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_HIDE, {
            node: this.node,
            hide: false
        });
    }

    handle_button_callback(event, customEventData) {
        if (customEventData === "close") {
            this.close();
        }
        this.xianshi_block_top();
    }
}

// 处理购买事件
function buyHandler(type, goodsId, count, price, context) {
    AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_jieshou_mianban({
        rewards: [{ goodsId: AL_GAME_HUA_GoodsConfig.GoodsId[goodsId], num: count }]
    });
    AL_GAME_HUA_Common.Common.bofang_yinxiao("game_coinscollect", context);

    const reportData = {
        source: AL_GAME_HUA_EventConfig.AssetsSource.coin,
        goodsList: [{ goods: AL_GAME_HUA_GoodsConfig.GoodsId[goodsId], num: count }]
    };

    if (type === 0 && price !== null) {
        reportData.goodsList.unshift({
            goods: AL_GAME_HUA_GoodsConfig.GoodsId.gold,
            num: -price
        });
        reportData.action = AL_GAME_HUA_EventConfig.AssetsAction.coin_get;
        AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportTransform(reportData);
    } else {
        reportData.action = type === 2 
            ? AL_GAME_HUA_EventConfig.AssetsAction.video_get 
            : AL_GAME_HUA_EventConfig.AssetsAction.share_get;
        AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportOutput(reportData);
    }
}

exports.default = CoinShop;